package com.example.administrator.x2picturetransliteration.Home.Presenter.Activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import com.example.administrator.x2picturetransliteration.Base.BasePresenter;
import com.example.administrator.x2picturetransliteration.Base.HttpGo;
import com.example.administrator.x2picturetransliteration.Bean.HttpDataBean;
import com.example.administrator.x2picturetransliteration.Constants;

import java.util.Map;

import rx.subscriptions.CompositeSubscription;

/**
 * 忘记密码
 * Created by Administrator on 2019/9/3.
 */

public class ForgetPresenter extends BasePresenter{

    public ForgetPresenter(Context context, CompositeSubscription mCompositeSubscription) {
        super(context, mCompositeSubscription);
    }

    /** 重置绑定密码短信 */
    public void sendResetSmsCode(Map<String,String> httpdata,boolean judge,final Callback mCallback){

        String url = judge?"sms_code/sendResetSmsCode":"sms_code/sendBindMobileSmsCode";

        mCompositeSubscription.add(

                mHttpGo.postSubscription(url, httpdata, new HttpGo.HttpGoCallback() {
                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HttpDataBean httpDataBean) {

                        if (httpDataBean.getCode()==0){

                            mCallback.getData(httpDataBean.getData());
                        }
                    }
                })
        );
    }

    /** 重置密码 */
    public void resetPassword(Map<String,String> httpdata){

        mCompositeSubscription.add(

                mHttpGo.postSubscription("user/resetPassword", httpdata, new HttpGo.HttpGoCallback() {
                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HttpDataBean httpDataBean) {

                        if (httpDataBean.getCode()==0)((Activity)context).finish();
                    }
                })
        );

    }

    /** 绑定手机号 */
    public void bindMobile(Map<String,String> httpdata){

        mCompositeSubscription.add(

                mHttpGo.postSubscription("user/bindMobile", httpdata, new HttpGo.HttpGoCallback() {
                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HttpDataBean httpDataBean) {

                        if (httpDataBean.getCode()==0){

                            Map<String,String> map = (Map<String,String>)httpDataBean.getData();
                            Constants.getConstants().setToken(map.get("token"));
                            Intent intent = ((Activity)context).getIntent();
                            ((Activity)context).setResult(Activity.RESULT_OK, intent);//返回页面
                            ((Activity)context).finish();
                        }
                    }
                })
        );

    }

}
